
#ifndef __2DDRAW_H__
#define __2DDRAW_H__

#include "basetype.h"
#include "3dDef.h"

#include "DxDrawEnv.h"


// directdraw pixel format defines, used to help
// bitmap loader put data in proper format
#define DD_PIXEL_FORMAT8        8
#define DD_PIXEL_FORMAT555      15
#define DD_PIXEL_FORMAT565      16
#define DD_PIXEL_FORMAT888      24
#define DD_PIXEL_FORMATALPHA888 32 
//



// root functions
USHORT RGB16Bit565(int r, int g, int b);
USHORT RGB16Bit555(int r, int g, int b);


#define BACK_SURFACE	0
#define PRIMARY_SURFACE 1



// DirectDraw wrap
class CDDraw : public DxDrawEnv
{
public:
	CDDraw();
	virtual ~CDDraw();

	int						Shutdown();

	int						Init(HWND hWnd, int width, int height, int bpp, BOOL bFullScreen = FALSE);
	LPDIRECTDRAWSURFACE7	Create_Surface(int width, int height, int mem_flags,  USHORT color_key_value = 0);

	int						Fill_Surface(USHORT color, int surface = 0, RECT *client = 0);
	int						Fill_Surface_Imp(LPDIRECTDRAWSURFACE7 lpdds, USHORT color, RECT *client = 0);
	LPDIRECTDRAWCLIPPER		Attach_Clipper(LPDIRECTDRAWSURFACE7 lpdds, int num_rects, LPRECT clip_list);

	int						Load_Palette_From_File(char *filename, LPPALETTEENTRY palette);
	int						Set_Palette(LPPALETTEENTRY set_palette);

	UCHAR*					Lock_Back_Surface();
	int						Unlock_Back_Surface();

	int						Flip(int winClient_x0, int winClient_y0);

	uint8*					GetBackBuffer()
	{
		return m_back_buffer;
	}

	int						GetBackLpitch()
	{
		return m_back_lpitch;
	}

	LPDIRECTDRAW7			GetDDraw()
	{
		return	m_lpdd;
	}

	LPDIRECTDRAWSURFACE7	GetSurface()
	{
		return m_lpddsprimary;
	}

	LPDIRECTDRAWSURFACE7	GetBackSurface()
	{
		return m_lpddsback;
	}

	PPALETTEENTRY	GetPalette(int color)
	{
		return &m_palette[color];
	}
};


#endif